home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / sticpsrc.lzh / SOURCE.ARC / NRCMD.C < prev    next >
C/C++ Source or Header  |  1990-05-10  |  24KB  |  1,076 lines

  1. /* NET/ROM user command processing */
  2.  
  3. #include <stdio.h>
  4. #include "global.h"
  5. #include "mbuf.h"
  6. #include "ax25.h"
  7. #include "timer.h"
  8. #include "netrom.h"
  9. #include "iface.h"
  10. #include "lapb.h"
  11. #include "cmdparse.h"
  12. #include <ctype.h>
  13.  
  14. static int dointerface(),dobcnodes(),donodetimer(),donrnodes(),donrroute(),
  15.     donrrts(),doobsotimer(),doparam(),donodefilter(),donrstat(),dotcpip(),
  16.     donrexclude(),donrinfo(),donrusers();
  17.  
  18. static struct cmds nrcmds[] = {
  19.     "bcnodes",    dobcnodes,    2,    "<interface>",    NULLCHAR,
  20.     "exclude",    donrexclude,    0,    NULLCHAR,    NULLCHAR,
  21.     "info",        donrinfo,    0,    NULLCHAR,    NULLCHAR,
  22.     "interface",    dointerface,    4,
  23.                 "<interface> <alias> <quality> [lap|uplink]",NULLCHAR,
  24.     "nodefilter",    donodefilter,    0,    NULLCHAR,    NULLCHAR,
  25.     "nodes",    donrnodes,    0,    NULLCHAR,    NULLCHAR,
  26.     "nodetimer",    donodetimer,    0,    NULLCHAR,    NULLCHAR,
  27.     "obsotimer",    doobsotimer,    0,    NULLCHAR,    NULLCHAR,
  28.     "param",    doparam,    2,    "3|4 <params>", NULLCHAR,
  29.     "route",    donrroute,    0,    NULLCHAR,    NULLCHAR,
  30.     "routes",    donrrts,    0,    NULLCHAR,    NULLCHAR,
  31. #ifdef NETROM4
  32.     "status",    donrstat,    0,    NULLCHAR,    NULLCHAR,
  33. #endif
  34.     "tcpip",    dotcpip,    0,    NULLCHAR,
  35.                     "normal|link|broadcast|ignore [alias]",
  36. #ifdef NETROM4
  37.     "users",    donrusers,    0,    NULLCHAR,    NULLCHAR,
  38. #endif
  39.     NULLCHAR,    NULLFP,        0,
  40.         "?subcommands",
  41.     NULLCHAR
  42. };
  43.  
  44. char nr_savename[80] = "";        /* filename for route save */
  45. char nr_infname[80] = "";        /* filename for INFO output */
  46. #ifdef NETROM4
  47. struct interface *nr_lap = NULLIF;    /* Local Access Point interface */
  48. #endif
  49.  
  50. struct timer nodetimer;            /* timer for nodes broadcasts */
  51. static struct timer obsotimer;        /* timer for aging routes */
  52.  
  53. static char nonetrom[] = "Interface \"%s\" not for NET/ROM\n";
  54. static char baddest[] = "Bad destination callsign\n";
  55. static char badneigh[] = "Bad neighbor callsign\n";
  56. static char cr[] = "\r";
  57.  
  58. /* Command multiplexer */
  59. donetrom(argc,argv)
  60. int argc;
  61. char *argv[];
  62. {
  63.     return subcmd(nrcmds,argc,argv);
  64. }
  65.  
  66. static int dorouteadd(),doroutedrop(),dorouteinfo(),doroutesave();
  67.  
  68. static struct cmds routecmds[] = {
  69.     "add",    dorouteadd,    7,
  70.         "<dest> <alias> <quality> <obso> <interface> <neighbor>",
  71.         "add failed",
  72.     "drop", doroutedrop,    4,
  73.         "<destination>|* <interface> <neighbor>",
  74.         "drop failed",
  75.     "info", dorouteinfo,    2,
  76.         "<destination>",NULLCHAR,
  77.     "save", doroutesave,    0,
  78.         "[<filename>]",NULLCHAR,
  79.     NULLCHAR,    NULLFP, 0,
  80.         "?subcommands",
  81.         NULLCHAR
  82. };
  83.  
  84. /* Route command multiplexer */
  85. static
  86. donrroute(argc,argv)
  87. int argc;
  88. char *argv[];
  89. {
  90.     if (argc < 2) {
  91.         doroutedump(NULLBUFP,0,1);
  92.         return 0;
  93.     }
  94.     return subcmd(routecmds,argc,argv);
  95. }
  96.  
  97. /* format alias:call in a static buffer */
  98. char *
  99. nr_fmtcall (rp)
  100. struct nrroute_tab *rp;
  101. {
  102.     static char buf[20];
  103.     char *cp;
  104.  
  105.     strcpy(buf,rp->alias);
  106.     /* remove trailing spaces */
  107.     if ((cp = index(buf,' ')) == NULLCHAR)
  108.         cp = &buf[strlen(buf)];
  109.     if (cp != buf)        /* don't include colon for null alias */ 
  110.         *cp++ = ':';
  111.     pax25(cp,&rp->call);
  112.     return buf;
  113. }
  114.  
  115. /* find out if an active crosslink exists to some neigbor */
  116. /* return it's axp, or NULLAX25 */
  117. static struct ax25_cb *
  118. nrcrosslink (np)
  119. struct nrnbr_tab *np;
  120. {
  121.     struct ax25_cb *find_ax25();
  122.     struct ax25_addr neighbor,*nr_scall();
  123.  
  124.     getaxaddr(&neighbor,np->call);
  125.  
  126.     return find_ax25(&neighbor,nr_scall(np->interface));
  127. }
  128.  
  129. /* Dump a list of known routes */
  130. /* also called from the NODES command of NET/ROM level 7 */
  131. doroutedump(bpp,hide,ext)
  132.     struct mbuf **bpp;        /* append to mbuf if non-NULL */
  133.     int hide;            /* hide #ALIAS nodes */
  134.     int ext;            /* extended listing (includes route) */
  135. {
  136.     register struct nrroute_tab *rp,*srp;
  137.     struct nrroute_tab *sortp = NULLNRRTAB;
  138.     struct nrroute_tab **prev;
  139.     int i,j;
  140.     char line[80],buf[20],tmp[10];
  141.  
  142.     if(ext){            /* put header above extended listing */
  143.         strcpy(line,"Call      Alias  Routing       Interf  Call      Alias  Routing       Interf");
  144.         if(bpp != NULLBUFP){
  145.         strcat(line,cr);
  146.         append(bpp,qstring(line));
  147.         } else
  148.         printf("%s\n",line);
  149.     }
  150.  
  151.     line[0] = '\0';
  152.  
  153.     /* first pass: every route is put in a sorted list */
  154.     for (i = 0; i < NRNUMCHAINS; i++)
  155.         for (rp = nrroute_tab[i]; rp != NULLNRRTAB; rp = rp->next) {
  156.         if(hide && rp->alias[0] == '#')
  157.             continue;        /* ignore #ALIAS nodes */
  158.  
  159.         /* insert this one in the list at the proper position */
  160.         for (srp = sortp,prev = &sortp; srp != NULLNRRTAB;
  161.              prev = &srp->sort, srp = srp->sort){
  162.             /* compare srp->call and rp->call */
  163.             for (j = 0; j < ALEN; j++)
  164.             if (srp->call.call[j] != rp->call.call[j])
  165.                 break;
  166.             if (j < ALEN){
  167.             if (uchar(srp->call.call[j]) > uchar(rp->call.call[j]))
  168.                 break;
  169.             } else {
  170.             if ((srp->call.ssid & SSID) > (rp->call.ssid & SSID))
  171.                 break;
  172.             }
  173.         }
  174.         rp->sort = srp;
  175.         *prev = rp;
  176.         }
  177.  
  178.     /* second pass: the routes are printed in sorted list order */
  179.     for (rp = sortp; rp != NULLNRRTAB; rp = rp->sort) {
  180.         if(!ext){
  181.         sprintf(line + strlen(line),"%-16s ",nr_fmtcall(rp));
  182.         } else {
  183.         pax25(tmp,&rp->call);
  184.         sprintf(line + strlen(line),"%-10s%-7s",tmp,rp->alias);
  185.         if (rp->routes == NULLNRBIND){
  186.             sprintf(line + strlen(line),"%-22s","no route");
  187.         } else {
  188.             if(addreq(&rp->call,rp->routes->via->call)){
  189.             strcpy(buf,"direct");
  190.             } else {
  191.             pax25(tmp,rp->routes->via->call);
  192.             sprintf(buf,"via %-9s",tmp);
  193.             }
  194.             sprintf(line + strlen(line),"%-13s %-8s",
  195.                 buf,rp->routes->via->interface->name);
  196.         }
  197.         }
  198.         if (strlen(line) > 65) {
  199.         if(bpp != NULLBUFP){
  200.             strcat(line,cr);
  201.             append(bpp,qstring(line));
  202.         } else
  203.             printf("%s\n",line);
  204.         line[0] = '\0';
  205.         }
  206.     }
  207.  
  208.     if (line[0])
  209.         if(bpp != NULLBUFP){
  210.         strcat(line,cr);
  211.         append(bpp,qstring(line));
  212.         } else
  213.         printf("%s\n",line);
  214.  
  215.     return 0;
  216. }
  217.  
  218. /* print detailed information on an individual route */
  219. static
  220. dorouteinfo(argc,argv)
  221. int argc;
  222. char *argv[];
  223. {
  224.     register struct nrroute_tab *rp;
  225.     struct ax25_addr dest;
  226.  
  227.     if (setcall(&dest,argv[1]) < 0) {
  228.         printf(baddest);
  229.         return -1;
  230.     }
  231.  
  232.     if ((rp = find_nrroute(&dest)) == NULLNRRTAB) {
  233.         printf("no such route\n");
  234.         return -1;
  235.     }
  236.  
  237.     printf("CP Qual Obso Interf Neighbor     Node: ");
  238.     nrrouteinfo(NULLBUFP,rp);
  239.     return 0;
  240. }
  241.  
  242. /* show route info for some callsign */
  243. /* also called from the NODES command of NET/ROM level 7 */
  244. nrrouteinfo (bpp,rp)
  245. struct mbuf **bpp;            /* append to this mbuf if non-null */
  246. register struct nrroute_tab *rp;
  247.  
  248. {
  249.     register struct nr_bind *bp;
  250.     register struct nrnbr_tab *np;
  251.     char neighbor[60];
  252.     char line[80];
  253.  
  254.     strcpy(line,nr_fmtcall(rp));
  255.     if(bpp != NULLBUFP){
  256.         strcat(line,cr);
  257.         append(bpp,qstring(line));
  258.     } else
  259.         printf("%s\n",line);
  260.  
  261.     for (bp = rp->routes; bp != NULLNRBIND; bp = bp->next) {
  262.         np = bp->via;
  263.         psax25(neighbor,np->call);
  264.         sprintf(line,"%c%c  %3d  %3d %-6s %s",
  265.             (nrcrosslink(np) != NULLAX25 ? '>' : ' '),
  266.             (bp->flags & NRB_PERMANENT ? 'P' : ' '),
  267.             bp->quality,bp->obsocnt,
  268.             np->interface->name,
  269.             neighbor);
  270.  
  271.         if(bpp != NULLBUFP){
  272.         strcat(line,cr);
  273.         append(bpp,qstring(line));
  274.         } else
  275.         printf("%s\n",line);
  276.     }
  277. }
  278.  
  279. /* show routes to NET/ROM neighbors */
  280. /* also called from the ROUTES command of NET/ROM level 7 */
  281. nrrtsdump (bpp)
  282. struct mbuf **bpp;            /* append to this mbuf if non-null */
  283. {
  284.     struct nrnbr_tab *np;
  285.     int i;
  286.     char tmp[60];
  287.     char line[80];
  288.  
  289.     for (i = 0; i < NRNUMCHAINS; i++)
  290.         for (np = nrnbr_tab[i]; np != NULLNTAB; np = np->next){
  291.         psax25(tmp,np->call);
  292.         sprintf(line,"%c %-6s %3d %3d %-9s",
  293.             (nrcrosslink(np) != NULLAX25 ? '>' : ' '),
  294.             np->interface->name,
  295.             np->interface->nriface->quality,
  296.             np->refcnt,tmp);
  297.  
  298.         if (np->failcnt != 0) {
  299.             sprintf(tmp,"  (%d link failure%s)",
  300.             np->failcnt,(np->failcnt != 1)? "s":"");
  301.             strcat(line,tmp);
  302.         }
  303.  
  304.         if(bpp != NULLBUFP){
  305.             strcat(line,cr);
  306.             append(bpp,qstring(line));
  307.         } else
  308.             printf("%s\n",line);
  309.         }
  310. }
  311.  
  312. /* set filename for INFO output */
  313. static
  314. donrinfo(argc,argv)
  315. int argc;
  316. char *argv[];
  317. {
  318.     if (argc < 2)